package com.zys.sac.core.handler;

import com.zys.sac.core.constant.RequestStatus;
import com.zys.sac.core.util.ServletResponseUtils;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 认证失败处理器，认证失败后会调用该处理器
 *
 * Created by zhongjunkai on 2022/3/11.
 */
public class SacAuthenticationFailureHandler implements AuthenticationFailureHandler {

    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) throws IOException, ServletException {
        ServletResponseUtils.render(response, ServletResponseUtils.result(RequestStatus.FAILURE.getCode(), e.getMessage()));
    }
}
